package com.selfdriving.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.selfdriving.BaseFragmentActivity;
import com.selfdriving.R;
import com.selfdriving.bean.Buy;
import com.selfdriving.utils.ViewFlipperView;

public class ActivityBuyExamine extends BaseFragmentActivity implements
		OnClickListener
{
	private TextView viewFlipperText;
	private LinearLayout VFlayout;
	private TextView title;
	private ImageButton imgBreak;
	int Pointe = 0;
	private LinearLayout linearLayout4;
	private TextView linearText1;
	private TextView linearText2;
	private TextView linearText3;
	private TextView linearText4;
	private TextView linearText5;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.activity_buy_examine);
		initViews();
		initEvents();
	}

	@Override
	protected void initViews()
	{
		linearLayout4 = (LinearLayout) super.findViewById(R.id.food_Linear4);
		linearText1 = (TextView) super.findViewById(R.id.food_Linear1_context);
		linearText2 = (TextView) super.findViewById(R.id.food_Linear2_context);
		linearText3 = (TextView) super.findViewById(R.id.food_Linear3_context);
		linearText4 = (TextView) super.findViewById(R.id.food_Linear4_context);
		linearText5 = (TextView) super.findViewById(R.id.food_Linear5_context);
		viewFlipperText = (TextView) super.findViewById(R.id.viewflipper_size);
		VFlayout = (LinearLayout) super.findViewById(R.id.vf_layout);
		title = (TextView) super.findViewById(R.id.top_text_middle);
		Buy buy = (Buy) mApplication.listBuy.get(0);
		title.setText(buy.getName());
		linearText1.setText(buy.getContent());
		linearText2.setText(buy.getAds());
		linearText3.setText("￥" + buy.getPrice());
		linearText4.setText(buy.getTel());
		linearText5.setText(buy.getTime());
		imgBreak = (ImageButton) super.findViewById(R.id.head_break);
		imgBreak.setVisibility(View.VISIBLE);
		if (buy.getImg4() != null)
		{
			mApplication.viewImg = new String[5];
			mApplication.viewImg[0] = buy.getImg0();
			mApplication.viewImg[1] = buy.getImg1();
			mApplication.viewImg[2] = buy.getImg2();
			mApplication.viewImg[3] = buy.getImg3();
			mApplication.viewImg[4] = buy.getImg4();
		} else if (buy.getImg3() != null)
		{
			mApplication.viewImg = new String[4];
			mApplication.viewImg[0] = buy.getImg0();
			mApplication.viewImg[1] = buy.getImg1();
			mApplication.viewImg[2] = buy.getImg2();
			mApplication.viewImg[3] = buy.getImg3();
		} else if (buy.getImg2() != null)
		{
			mApplication.viewImg = new String[3];
			mApplication.viewImg[0] = buy.getImg0();
			mApplication.viewImg[1] = buy.getImg1();
			mApplication.viewImg[2] = buy.getImg2();
		} else if (buy.getImg1() != null)
		{
			mApplication.viewImg = new String[2];
			mApplication.viewImg[0] = buy.getImg0();
			mApplication.viewImg[1] = buy.getImg1();
		} else if (buy.getImg0() != null)
		{
			mApplication.viewImg = new String[1];
			mApplication.viewImg[0] = buy.getImg0();
		}
		ViewFlipperView flipperView = new ViewFlipperView(mApplication,
				ActivityBuyExamine.this, viewFlipperText, 2,
				mApplication.listBuy, Pointe);
		VFlayout.addView(flipperView.viewFlipper, layoutParams);
	}

	@Override
	protected void initEvents()
	{
		// TODO Auto-generated method stub
		imgBreak.setOnClickListener(this);
		linearLayout4.setOnClickListener(this);

	}

	@Override
	public void onClick(View v)
	{
		// TODO Auto-generated method stub
		switch (v.getId())
		{
		case R.id.head_break:
			finish();
			break;
		case R.id.food_Linear4:
			Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel://"
					+ linearText4.getText().toString().trim()));
			startActivity(intent);
			break;
		}
	}

}
